import { defineStore } from 'pinia';

export const useMenuStore = defineStore('menu', {
  state: () => ({
    activeMenuKey: localStorage.getItem('activeMenuKey') || '',
  }),
  actions: {
    setActiveMenu(key) {
      this.activeMenuKey = key;
      // 使用localStorage保存，确保刷新后仍然可用
      localStorage.setItem('activeMenuKey', key);
    },
    clearActiveMenu() {
      this.activeMenuKey = '';
      localStorage.removeItem('activeMenuKey');
    },
  },
});
